<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <i class="fa fa-tachometer" aria-hidden="true"></i> 商品管理
        <small>编辑</small>
      </h1>
    </section>
    <section class="content">
    	<div class="box box-primary">
    		<div class="box-header with-border">
    			<h3 class="box-title"><?=!isset($goods->id) ? 'ID#New' : 'ID#'.$goods->id?></h3>
    		</div>
    		<form role="form" id="goodsForm">
                <?php if(isset($goods->id)) { ?>
                    <input type="hidden" name="id" value="<?=$goods->id?>">
                <?php } ?>
    			<div class="box-body">
    				<div class="row">
    					<div class="col-lg-6">
    						<div class="form-group">
		    					<label for="">型号</label>
		    					<input type="text" class="form-control" name="spec_no" value="<?=$goods->spec_no?>">
		    				</div>
    					</div>
    					<div class="col-lg-6">
    						<div class="form-group">
		    					<label for="">商品名称</label>
		    					<input type="text" class="form-control" name="goods_name" value="<?=$goods->goods_name?>">
		    				</div>
    					</div>
    				</div>

    				<div class="row">
    					<div class="col-lg-6">
    						<div class="form-group">
		    					<label for="">单价（$）</label>
		    					<input type="text" class="form-control" name="price" value="<?=$goods->price?>">
		    				</div>
    					</div>
    					<div class="col-lg-6">
    						<div class="form-group">
		    					<label for="">单件重量（kg）</label>
		    					<input type="text" class="form-control" name="piece_weight" value="<?=$goods->piece_weight?>">
		    				</div>
    					</div>
    				</div>


    				<div class="row">
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">彩盒长度（mm）</label>
		    					<input type="text" class="form-control" name="gift_length" value="<?=$goods->gift_length?>">
		    				</div>
    					</div>
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">彩盒宽度（mm）</label>
		    					<input type="text" class="form-control" name="gift_width" value="<?=$goods->gift_width?>">
		    				</div>
    					</div>
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">彩盒高度（mm）</label>
		    					<input type="text" class="form-control" name="gift_height" value="<?=$goods->gift_height?>">
		    				</div>
    					</div>
    				</div>


    				<div class="row">
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">外箱长度（mm）</label>
		    					<input type="text" class="form-control" name="box_length" value="<?=$goods->box_length?>">
		    				</div>
    					</div>
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">外箱宽度（mm）</label>
		    					<input type="text" class="form-control" name="box_width" value="<?=$goods->box_width?>">
		    				</div>
    					</div>
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">外箱高度（mm）</label>
		    					<input type="text" class="form-control" name="box_height" value="<?=$goods->box_height?>">
		    				</div>
    					</div>
    				</div>

    				<div class="row">
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">每箱数量(件)</label>
		    					<input type="text" class="form-control" name="package_count" value="<?=$goods->package_count?>">
		    				</div>
    					</div>
    					<div class="col-lg-4">
    						<div class="form-group">
		    					<label for="">箱子总重量(KG)</label>
		    					<input type="text" class="form-control" name="package_weight" value="<?=$goods->package_weight?>">
		    				</div>
    					</div>
    				</div>
    			</div>
                
    			<div class="box-footer text-center">
    				<button class="btn btn-primary goodsSaveBtn">保存</button>
                    <a class="btn btn-info" href="/goods">返回</a>
    			</div>
    		</form>
    	</div>
    </section>

    <script type="text/javascript">
    	$(function(){
    		$('.goodsSaveBtn').on('click', function(e){
    			e.preventDefault();
    			var goodsData = {};
    			var formData = $('#goodsForm').serializeArray();
    			$.each(formData, function(){
    				goodsData[this.name] = this.value;
    			})
                $.post('/goods/save',{
                    goods: goodsData
                }).then(function(res){
                    toastr.success(res.message, '保存成功')
                }, function(err) {
                    let error = err.responseJSON;
                    toastr.error(error.message, '保存失败')

                })
    			
    			return false;
    		})
    	})
    </script>
</div>